﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AspCategoriesEdit
{
    public partial class Delete : System.Web.UI.Page
    {
        private int id;

        protected void Page_Load(object sender, EventArgs e)
        {
            id = Convert.ToInt32(Request.Params["id"]);

            if (!Page.IsPostBack)
            {
                var res = DataLayer.FindCategoryById(id);
                if (res != null)
                {
                    warningLbl.Text = "Are you sure you want to delete " + res.CategoryName + " ?";
                }
            }
        }

        protected void yesBtn_Click(object sender, EventArgs e)
        {
            try
            {
                DataLayer.Delete(id);
                Response.Redirect("Default.aspx");
            }
            catch (Exception)
            {
                yesBtn.Enabled = false;
                errorLbl.Text = "Sorry you can not delete that category :/";
            }
        }

        protected void noBtn_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx");
        }
    }
}